package com.zhangjingcheng.yunyixia.controller;

import com.zhangjingcheng.yunyixia.pojo.dto.GetShareFileDTO;
import com.zhangjingcheng.yunyixia.pojo.dto.ShareDTO;
import com.zhangjingcheng.yunyixia.pojo.dto.ShareListDTO;
import com.zhangjingcheng.yunyixia.pojo.vo.ShareListVO;
import com.zhangjingcheng.yunyixia.pojo.vo.ShareUserVO;
import com.zhangjingcheng.yunyixia.pojo.vo.ShareVO;
import com.zhangjingcheng.yunyixia.result.PageResult;
import com.zhangjingcheng.yunyixia.result.Result;
import com.zhangjingcheng.yunyixia.service.ShareService;
import io.swagger.annotations.ApiOperation;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/share")
public class ShareController {

    @Autowired
    private ShareService shareService;

    /**
     * 文件分享
     *
     * @param shareDTO
     * @return
     */
    @ApiOperation("文件分享")
    @PostMapping()
    public Result<ShareVO> share(@RequestBody ShareDTO shareDTO) {
        log.info("开始文件分享：{}", shareDTO);
        return Result.success(shareService.share(shareDTO));
    }

    /**
     * 批量取消分享
     *
     * @param ids
     * @return
     */
    @ApiOperation("批量取消分享")
    @DeleteMapping("/cancelShare")
    public Result<String> cancelShare(@RequestBody List<Integer> ids) {// 分享id
        shareService.cancelShare(ids);
        return Result.success();
    }

    /**
     * 获取分享文件列表
     *
     * @param dto
     * @return
     */
    @ApiOperation("获取分享文件列表")
    @GetMapping("/list")
    public Result<PageResult<ShareListVO>> list(ShareListDTO dto) {// 用户id
        log.info("开始获取分享文件列表：{}", dto);
        return Result.success(shareService.list(dto));
    }


    /**
     * 获取分享文件信息
     *
     * @param id
     * @return
     */
    @ApiOperation("获取分享文件信息")
    @GetMapping("/getShareFileInfo")
    public Result<ShareUserVO> getShareFileInfo(Integer id) {// 分享id
        return Result.success(shareService.getShareFileInfo(id));
    }

    /**
     * 获取分享文件(下载)
     *
     * @param dto
     */
    @ApiOperation("下载分享文件")
    @GetMapping("/download")
    public void getShareFile(GetShareFileDTO dto, HttpServletResponse response) {
        shareService.getShareFile(dto, response);
    }

    /**
     * 获取提取码
     *
     * @param id
     * @return
     */
    @ApiOperation("获取下载链接")
    @GetMapping("/getDownloadCode")
    public Result<String> getDownloadCode(Integer id) {
        return Result.success(shareService.getDownloadCode(id));
    }

}
